home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / makmenu2.zip / MAKMENU2.BAS next >
BASIC Source File  |  1989-08-09  |  8KB  |  257 lines

  1. FUNCTION MakMenu2% (choozit$(), NumofChoices%, LeftColumn%, Row%, fg%, bg%, fgl%, hfg%, hbg%)
  2.  
  3. REDIM firstletter$(NumofChoices%), spot%(NumofChoices%), temp$(NumofChoices%)
  4.  
  5. '=== Set local variables - extended scan codes for keypad keys
  6.  
  7. piknumber = 0
  8. Up$ = CHR$(0) + CHR$(72)
  9. Down$ = CHR$(0) + CHR$(80)
  10. Enter$ = CHR$(13)
  11. Home$ = CHR$(0) + CHR$(71)
  12. End$ = CHR$(0) + CHR$(79)
  13. PgUp$ = CHR$(0) + CHR$(73)
  14. PgDn$ = CHR$(0) + CHR$(81)
  15. esc$ = CHR$(0) + CHR$(27)
  16.  
  17. '=== Check for out-of-bounds parameters.  If any are out of range, quit the function
  18.  
  19. IF NumofChoices% < 2 OR NumofChoices% > 23 THEN EXIT FUNCTION
  20. IF LeftColumn% < 1 OR LeftColumn% > 80 THEN EXIT FUNCTION
  21. IF Row% < 1 OR Row% > 23 OR (Row% + NumofChoices%) > 24 THEN EXIT FUNCTION
  22.  
  23. '=== Calculate length of longest menu choice and store value in ChoiceLen%
  24.  
  25. choicelen% = 0
  26. FOR x% = 1 TO NumofChoices%
  27.         IF LEN(choozit$(x%)) > choicelen% THEN
  28.                 choicelen% = LEN(choozit$(x%))
  29.         END IF
  30. NEXT x%
  31.  
  32. '=== Check to make sure longest menu choice will fit on screen
  33.  
  34. IF (LeftColumn% + choicelen%) > 80 THEN EXIT FUNCTION
  35.  
  36. '=== Put first character of each choice in firstletter$()
  37.  
  38. FOR x% = 1 TO NumofChoices%
  39.         firstletter$(x%) = UCASE$(LEFT$(choozit$(x%), 1))
  40.         spot%(x%) = x%
  41. NEXT x%
  42.  
  43. '=== Sort the firstletter$ array
  44.  
  45. CALL QwikSort(firstletter$(), spot%(), NumofChoices%)
  46.  
  47. '=== Move firstletter$() into array with variables in ascending alpha order
  48.  
  49. FOR I = 1 TO NumofChoices%
  50.         temp$(I) = firstletter$(spot%(I))
  51. NEXT I
  52.  
  53. '=== Set flag if number of choices<=10.  Then add integers to menu if set.
  54.  
  55. IF NumofChoices% <= 10 THEN
  56.         piknumber = 1
  57.         choicelen% = choicelen% + 4
  58.         IF (LeftColumn% + choicelen%) > 80 THEN EXIT FUNCTION
  59. END IF
  60.  
  61. SELECT CASE NumofChoices%
  62.  
  63.         CASE 0 TO 9
  64.  
  65.         min$ = CHR$(49)
  66.  
  67.         CASE 10
  68.  
  69.         min$ = CHR$(48)
  70.  
  71.         CASE IS > 10
  72.  
  73.         min$ = ""
  74.         max$ = ""
  75.  
  76. END SELECT
  77.  
  78. IF NumofChoices% <= 10 THEN max$ = CHR$(48 + NumofChoices%)
  79.  
  80. '=== Print menu choices to screen
  81.        
  82.                 FOR x% = 1 TO NumofChoices%
  83.                         LOCATE (Row% - 1) + x%, LeftColumn%
  84.                         COLOR fgl%, bg%
  85.                         IF piknumber THEN
  86.                                 seq = x%
  87.                                 IF x% = 10 THEN seq = 0
  88.                                 PRINT RIGHT$(STR$(seq), 1); " - "; LEFT$(choozit$(x%), 1);
  89.                                 COLOR fg%, bg%
  90.                                 PRINT RIGHT$(choozit$(x%), LEN(choozit$(x%)) - 1)
  91.                         ELSE
  92.                                 PRINT LEFT$(choozit$(x%), 1);
  93.                                 COLOR fg%, bg%
  94.                                 PRINT RIGHT$(choozit$(x%), LEN(choozit$(x%)) - 1)
  95.                         END IF
  96.                 NEXT x%
  97.  
  98. '=== Highlight the first entry in the list.
  99.  
  100.         currentlocation% = 1
  101.         COLOR hfg%, hbg%
  102.         LOCATE (Row% - 1) + currentlocation%, LeftColumn%
  103.         PRINT SPACE$(choicelen%)
  104.        
  105.         LOCATE (Row% - 1) + currentlocation%, LeftColumn%
  106.         IF piknumber THEN PRINT "1 - ";
  107.         PRINT choozit$(currentlocation%)
  108.  
  109. '=== Read keystrokes and change the highlighted entry appropriately
  110.  
  111.         ExitCode = false
  112.         WHILE ExitCode = false
  113.  
  114.         '=== Read keystrokes
  115.  
  116.                 key$ = ""
  117.                 WHILE key$ = ""
  118.                         LET key$ = UCASE$(INKEY$)
  119.                 WEND
  120.         SELECT CASE key$
  121.          
  122.                 '=== Legal movement
  123.                 CASE Up$, Down$, Home$, End$, PgUp$, PgDn$, min$ TO max$, temp$(1) TO temp$(NumofChoices%)
  124.  
  125.                         '=== Restore old highlighted choice to normal colors
  126.          
  127.                         LOCATE (Row% - 1) + currentlocation%, LeftColumn%
  128.                         COLOR fg%, bg%: PRINT SPACE$(choicelen%)
  129.                         COLOR fgl%, bg%
  130.                         LOCATE (Row% - 1) + currentlocation%, LeftColumn%
  131.                         IF piknumber THEN
  132.                                 PRINT RIGHT$(STR$(currentlocation%), 1); " - "; LEFT$(choozit$(currentlocation%), 1);
  133.                                 COLOR fg%, bg%
  134.                                 PRINT RIGHT$(choozit$(currentlocation%), LEN(choozit$(currentlocation%)) - 1)
  135.                         ELSE
  136.                                 PRINT LEFT$(choozit$(currentlocation%), 1);
  137.                                 COLOR fg%, bg%
  138.                                 PRINT RIGHT$(choozit$(currentlocation%), LEN(choozit$(currentlocation%)) - 1)
  139.                  
  140.                         END IF
  141.  
  142.                 CASE ELSE
  143.  
  144.                         'Nothing
  145.  
  146.         END SELECT
  147.  
  148. '=== Update the highlight bar's location based on which key was hit
  149.  
  150.  
  151.         SELECT CASE key$
  152.  
  153.                 CASE Up$
  154.            
  155.                         '=== Set new CurrentLocation%
  156.  
  157.                         IF currentlocation% = 1 THEN
  158.                                 currentlocation% = NumofChoices%
  159.                         ELSE
  160.                                 currentlocation% = currentlocation% - 1
  161.                         END IF
  162.            
  163.                 CASE Down$
  164.         
  165.                         '=== Set New CurrentLocation%
  166.  
  167.                         IF currentlocation% = NumofChoices% THEN
  168.                                 currentlocation% = 1
  169.                         ELSE
  170.                                 currentlocation% = currentlocation% + 1
  171.                         END IF
  172.  
  173.                 CASE Enter$
  174.  
  175.                         '=== Set makmenu2 to highlighted selection and exit ===
  176.  
  177.                         MakMenu2% = currentlocation%
  178.  
  179.                         '=== Instead of using ExitCode to beak out of this, we have to use
  180.                         '=== EXIT FUNCTION, or it never quits.
  181.  
  182.                         EXIT FUNCTION
  183.  
  184.                 CASE Home$, PgUp$
  185.            
  186.                         '=== Set New CurrentLocation%
  187.  
  188.                         currentlocation% = 1
  189.  
  190.                 CASE End$, PgDn$
  191.  
  192.                         '=== Set New CurrentLocation%
  193.                                                                            
  194.                         currentlocation% = NumofChoices%
  195.        
  196.                 CASE min$ TO max$
  197.  
  198.                         IF piknumber THEN
  199.                       
  200.                                 IF NumofChoices% = 10 AND VAL(key$) = 0 THEN
  201.                                         currentlocation% = NumofChoices%
  202.                                  ELSE
  203.                                         currentlocation% = VAL(key$)
  204.                                 END IF
  205.  
  206.                         END IF
  207.  
  208.                 CASE temp$(1) TO temp$(NumofChoices%)
  209.  
  210.                         oldspot% = currentlocation%
  211.                         FOR x% = 1 TO NumofChoices%
  212.  
  213.                                 IF temp$(x%) = key$ THEN
  214.                                         currentlocation% = spot%(x%)
  215.                                         GOTO done
  216.                                 END IF
  217.  
  218.                         NEXT x%
  219.  
  220.                         IF currentlocation% = oldspot% THEN BEEP
  221.        
  222.                 CASE ELSE
  223.  
  224.                         'Illegal key - leave everything as is
  225.                         BEEP
  226.  
  227. done:
  228.  
  229.         END SELECT
  230.  
  231. '=== Highlight the entry indicated by CurrentLocation%
  232.  
  233.         SELECT CASE key$
  234.    
  235.         CASE Up$, Down$, Home$, End$, PgUp$, PgDn$, min$ TO max$, temp$(1) TO temp$(NumofChoices%)
  236.  
  237.                         '=== Highlight new choice
  238.   
  239.                         COLOR hfg%, hbg%
  240.                         LOCATE (Row% - 1) + currentlocation%, LeftColumn%
  241.                         IF piknumber THEN
  242.                                 PRINT RIGHT$(STR$(currentlocation%), 1); " - "; choozit$(currentlocation%)
  243.                         ELSE
  244.                                 PRINT choozit$(currentlocation%)
  245.                         END IF
  246.  
  247.         CASE ELSE
  248.  
  249.                         'Nothing
  250.  
  251.         END